﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SmackTalk : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void LoadMessages(Week week, User user)
    {
        List<Message> messages = DataBase.Messages.GetWeekMessages(week);
        var id = week.ID;

        if (user == null)
            sendmessage.Disabled = true;
        else
            userID.Value = user.ID.ToString();

        weekID.Value = id.ToString();

        InsertMessage(messages);
    }

    private void InsertMessage(List<Message> messages)
    {

        StringBuilder html = new StringBuilder();

        foreach (var m in messages)
        {
            if(m.Computer)
                html.AppendLine(string.Format("<div><span class='message {0}'>:   {1}</div></li>", m.Style, m.Note));
            else
                html.AppendLine(string.Format("<div><span class='user'>{0}</span><span class='messagedate'>({1})</span><span class='message'>:   {2}</div></li>", m.UserNickName, m.Date.ToString("g"), m.Note));
        }
        lstMessage.InnerHtml = html.ToString();
    }
}